﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace Model
{
    public partial class Certificate
    {
        public enum Permission : int
        {
            None = 0,
            /// <summary>
            /// 用户管理
            /// </summary>
            Certificate = 1,
            /// <summary>
            /// 病例管理
            /// </summary>
            Diagnosis = 2,
            /// <summary>
            /// 药剂管理
            /// </summary>
            Drugs = 4,
            /// <summary>
            /// 客户管理
            /// </summary>
            UserBase = 8,
        }


        public bool HasPermission(Permission p)
        {
            if (((int)p & Permissions) == 0)
                return false;
            else
                return true;
        }

        public void SetPermission(Permission p)
        {
            switch (p)
            {
                case Permission.None:
                    this.Permissions = 0; break;
                case Permission.Certificate:
                    this.Permissions |= 1; break;
                case Permission.Diagnosis:
                    this.Permissions |= 2; break;
                case Permission.Drugs:
                    this.Permissions |= 4; break;
                case Permission.UserBase:
                    this.Permissions |= 8; break;
            }
        }

        #region RenderList

        public string RenderList_Permission
        {
            get
            {
                StringBuilder sb = null;

                if (HasPermission(Permission.Certificate))
                {
                    sb = new StringBuilder();
                    sb.Append("用户管理");
                }
                if (HasPermission(Permission.Diagnosis))
                {
                    if (sb == null) sb = new StringBuilder(); else sb.Append("|");
                    sb.Append("病例管理");
                }
                if (HasPermission(Permission.Drugs))
                {
                    if (sb == null) sb = new StringBuilder(); else sb.Append("|");
                    sb.Append("药剂管理");
                }
                if (HasPermission(Permission.UserBase))
                {
                    if (sb == null) sb = new StringBuilder(); else sb.Append("|");
                    sb.Append("客户管理");
                }
                if (sb != null)
                    return sb.ToString();
                else
                    return null;
            }
        }

        public string RenderList_Status
        {
            get
            {
                switch (this.Status)
                {
                    case 1:
                        return "正常";
                    case -1:
                        return "已删除";
                    default:
                        return "-";
                }
            }

        }

        #endregion
    }
}
